#!/usr/bin/python
# -*-coding:UTF-8 -*-

# ========================
# @Time  : 2021/3/25
# @Author: Sunny
# ========================


import requests

from flask import Flask,request,jsonify,render_template
from hashlib import md5
# from flask_bootstrap import Bootstrap

app = Flask(__name__)

#密码使用md5加密
m = md5()
m.update('lemonban'.encode('utf-8'))
pwd = m.hexdigest()

#测试数据
user_info = {'user': 'python01','pwd':pwd}

project_data = {'code':'1',
                'data':[{'title':'前程贷','id':'1001'},
                        {'title':'智慧金融','id':'1002'},
                        {'title':'生鲜到家','id':'1003'},
                        {'title':'柠檬班app','id':'1004'},
                        ],
                'msg':'四个项目'

}

#接口数据
interface_data = {
    "1001":{'code':'1',
            'data':[{'name':'前程贷登录1001'},
                    {'name':'前程贷注册1001'}],
            'msg':'2个接口'
            },

    "1002":{'code': '1',
            'data': [{'name': '智慧登录1002'},
                    {'name': '智慧注册1002'},
                     {'name': '智慧贷款1004'}],
            'msg': '3个接口'
    },

    "1003": {'code': '1',
             'data': [{'name': '生鲜-登录1003'},
                      {'name': '生鲜-注册1003'},
                      {'name': '生鲜下单1003'}],
             'msg': '3个接口'
             },

    "1004": {'code': '1',
             'data': [{'name': 'app登录1004'},
                      {'name': 'app注册1004'},
                      {'name': 'app报名1004'}],
             'msg': '3个接口'
             }
}


#首页
@app.route('/index',methods=['get'])
def index():
    return render_template('html.html')

#首页
@app.route('/',methods=['get'])
def login_page():
    return render_template('login.html')

#登录
@app.route('/login',methods=['post'])
def login():
    #获取以post方式提交的数据(接收form提交来的数据)
    data = request.form
    print(pwd,data.get('pwd'))
    #判断账号是否正确
    if user_info.get('user') == data.get('user') and user_info.get('pwd') == data.get('pwd'):
        return jsonify({'code':'1','data':None,'msg':'成功'})
    else:
        return jsonify({'code':'0','data':None,'msg':'密码有误'})

#获取项目列表
@app.route('/pro_list',methods=['get'])
def pro_list():
    return jsonify(project_data)


if __name__ == '__main__':
    app.run(debug=True)

# bootstrap = Bootstrap(app)
